import { GameError } from './GameError';

/**
 * 背包相关错误类
 */

/**
 * 背包已满错误
 */
export class BagFullError extends GameError {
    readonly code = 'BAG_FULL';
    readonly statusCode = 400;

    constructor(currentSize?: number, maxSize?: number) {
        const message = currentSize && maxSize 
            ? `背包已满，当前容量：${currentSize}/${maxSize}`
            : '背包已满，无法添加更多物品';
        super(message, { currentSize, maxSize });
    }
}

/**
 * 物品不存在错误
 */
export class ItemNotFoundError extends GameError {
    readonly code = 'ITEM_NOT_FOUND';
    readonly statusCode = 404;

    constructor(itemId: string, itemType?: string) {
        super(`物品不存在：${itemId}`, { itemId, itemType });
    }
}

/**
 * 物品不足错误
 */
export class InsufficientItemError extends GameError {
    readonly code = 'INSUFFICIENT_ITEM';
    readonly statusCode = 400;

    constructor(itemName: string, required: number, available: number) {
        super(`${itemName}数量不足，需要：${required}，拥有：${available}`, {
            itemName,
            required,
            available
        });
    }
}

/**
 * 物品类型错误
 */
export class InvalidItemTypeError extends GameError {
    readonly code = 'INVALID_ITEM_TYPE';
    readonly statusCode = 400;

    constructor(expectedType: string, actualType: string) {
        super(`物品类型错误，期望：${expectedType}，实际：${actualType}`, {
            expectedType,
            actualType
        });
    }
}

/**
 * 物品使用限制错误
 */
export class ItemUsageRestrictedError extends GameError {
    readonly code = 'ITEM_USAGE_RESTRICTED';
    readonly statusCode = 403;

    constructor(itemName: string, restriction: string) {
        super(`物品 ${itemName} 使用受限：${restriction}`, {
            itemName,
            restriction
        });
    }
}

/**
 * 背包操作错误
 */
export class BagOperationError extends GameError {
    readonly code = 'BAG_OPERATION_ERROR';
    readonly statusCode = 500;

    constructor(operation: string, reason: string) {
        super(`背包操作失败：${operation}，原因：${reason}`, {
            operation,
            reason
        });
    }
}
